package service

import (
	"singo/model"
	"singo/serializer"
)

// MistakeUpdateService 更新错误日志的服务
type MistakeUpdateService struct {
	ID     string `form:"id" json:"id" binding:"required"`
	Status uint   `form:"status" json:"status"`
}

// MistakeUpdate 更新错误日志
func (service *MistakeUpdateService) MistakeUpdate() *serializer.Response {
	var demand model.Mistake
	err := model.DB.First(&demand, "id = ?", service.ID).Error
	if err != nil {
		return &serializer.Response{
			Status: 404,
			Msg:    "不存在",
			Error:  err.Error(),
		}
	}

	if err = model.DB.Model(&demand).Where("id = ?", service.ID).Update("status", service.Status).Error; err != nil {
		return &serializer.Response{
			Status: 50002,
			Msg:    "错误日志任务保存失败",
			Error:  err.Error(),
		}
	}

	return &serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
